<?php
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2020/1/14
 * Time: 13:24
 */

namespace app\index\controller;


use app\IndexBaseController;
use think\facade\Db;
use tools\Curl;

class Video extends IndexBaseController
{
    function initialize()
    {
        parent::initialize();
        $url = $this->request->request('url');
        if($url==''){
            $this->error('地址不能为空');
        }
        $headers = array();
        foreach ($_SERVER as $key => $value) {
            if (substr($key, 0, 5) === 'HTTP_') {
                $key = substr($key, 5);
                $key = strtolower($key);
                $key = str_replace('_', ' ', $key);
                $key = ucwords($key);
                $key = str_replace(' ', '-', $key);
                $headers[$key] = $value;
            }
        }
        $this->header = $headers;
        $url =  $this->request->request('url');
        $this->playurl = str_replace("https://m.","https://www.",$url);
    }
//  http://api.ledboke.com/api.php?url=*&cb=
    function ledboke()
    {
        $tt = (string)($this->request->server('REQUEST_TIME_FLOAT'));
        $tt = str_replace('.','',$tt);
        $tt = substr($tt,0,13);
        list($msec, $sec) = explode(' ', microtime());
        $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
        $u = $this->playurl.'&cb=jQuery1820'.'_'.$tt.'&_='.$msectime;
        $options = array(
            CURLOPT_URL => 'http://api.ledboke.com/api.php?url='.$u,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_ENCODING=>'gzip, deflate',
            CURLOPT_USERAGENT=>$this->header['User-Agent'],
            CURLOPT_REFERER=>'http://api.ledboke.com/?url='.$this->playurl,
            CURLOPT_HTTPHEADER => array(
                'Accept:text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
                'Accept-Language:zh-CN,zh;q=0.9',
                'Cache-Control:no-cache',
                'Connection:keep-alive',
                'Host:api.ledboke.com',
                'Pragma:no-cache',
                'X-Requested-With:XMLHttpRequest',
            ),
        );

        $ch = new Curl($options);
        $res = $ch->send();
//        $res['curl'] = 'jQuery1820_1584063838531({"success":1,"code":200,"title":"\u4f0d\u516d\u4e03\u4e4b\u6700\u5f3a\u53d1\u578b\u5e08","part":"10","url":"https:\/\/iqiyi.cdn9-okzy.com\/20200101\/4376_66093e7f\/index.m3u8","type":"hls","info":[{"flag":"ckm3u8","flag_name":"\u6e901","site":0,"part":10,"video":["\u7b2c01\u96c6$https:\/\/qq.com-ok-qq.com\/20191023\/24991_531bb6f4\/index.m3u8$ckm3u8","\u7b2c02\u96c6$https:\/\/qq.com-ok-qq.com\/20191023\/24990_accd8c04\/index.m3u8$ckm3u8","\u7b2c03\u96c6$https:\/\/qq.com-ok-qq.com\/20191030\/25261_c1bd0872\/index.m3u8$ckm3u8","\u7b2c04\u96c6$https:\/\/qq.com-ok-qq.com\/20191106\/25493_17d88741\/index.m3u8$ckm3u8","\u7b2c05\u96c6$https:\/\/qq.com-ok-qq.com\/20191113\/25764_dea0c0f8\/index.m3u8$ckm3u8","\u7b2c06\u96c6$https:\/\/qq.com-ok-qq.com\/20191204\/26477_04f2f3c7\/index.m3u8$ckm3u8","\u7b2c07\u96c6$https:\/\/qq.com-ok-qq.com\/20191211\/26765_e2939796\/index.m3u8$ckm3u8","\u7b2c08\u96c6$https:\/\/iqiyi.cdn9-okzy.com\/20191218\/3530_c2b24de9\/index.m3u8$ckm3u8","\u7b2c09\u96c6$https:\/\/iqiyi.cdn9-okzy.com\/20191225\/4066_55501a87\/index.m3u8$ckm3u8","\u7b2c10\u96c6$https:\/\/iqiyi.cdn9-okzy.com\/20200101\/4376_66093e7f\/index.m3u8$ckm3u8"]},{"flag":"zuidam3u8","flag_name":"\u6e902","site":1,"part":10,"video":["\u7b2c01\u96c6$https:\/\/hong.tianzhen-zuida.com\/20191023\/11776_97dcd961\/index.m3u8$zuidam3u8","\u7b2c02\u96c6$https:\/\/hong.tianzhen-zuida.com\/20191023\/11775_0ab7d69d\/index.m3u8$zuidam3u8","\u7b2c03\u96c6$https:\/\/hong.tianzhen-zuida.com\/20191106\/13145_35a8e34c\/index.m3u8$zuidam3u8","\u7b2c04\u96c6$https:\/\/meng.wuyou-zuida.com\/20191109\/21807_62188687\/index.m3u8$zuidam3u8","\u7b2c05\u96c6$https:\/\/hong.tianzhen-zuida.com\/20191113\/13705_1e4bf81d\/index.m3u8$zuidam3u8","\u7b2c06\u96c6$https:\/\/meng.wuyou-zuida.com\/20191204\/23219_80775a7e\/index.m3u8$zuidam3u8","\u7b2c07\u96c6$https:\/\/hong.tianzhen-zuida.com\/20191211\/15847_9076016d\/index.m3u8$zuidam3u8","\u7b2c08\u96c6$https:\/\/meng.wuyou-zuida.com\/20191218\/23883_3f0cd98b\/index.m3u8$zuidam3u8","\u7b2c09\u96c6$https:\/\/hong.tianzhen-zuida.com\/20191225\/16944_e1683e19\/index.m3u8$zuidam3u8","\u7b2c10\u96c6$https:\/\/mei.huazuida.com\/20200101\/20600_25da1fe8\/index.m3u8$zuidam3u8"]},{"flag":"wlm3u8","flag_name":"\u6e903","site":2,"part":10,"video":["\u7b2c1\u96c6$http:\/\/cn6.7639616.com\/hls\/20191025\/4a00545c347b6dce515fd2176ac3190b\/1571990593\/index.m3u8","\u7b2c2\u96c6$http:\/\/cn6.7639616.com\/hls\/20191025\/62bca6384f91cb38d35dc8bdfa18317a\/1571990691\/index.m3u8","\u7b2c3\u96c6$http:\/\/cn2.7639616.com\/hls\/20191031\/9589146b0c4f8e0ab387a3be6ea0ce86\/1572496999\/index.m3u8","\u7b2c4\u96c6$http:\/\/cn7.7639616.com\/hls\/20191106\/18dc5b60d8a240f2b3e178a117de6639\/1573028580\/index.m3u8","\u7b2c5\u96c6$http:\/\/cn7.7639616.com\/hls\/20191117\/5b1cd3398545c11a63610954201e788f\/1573979124\/index.m3u8","\u7b2c6\u96c6$http:\/\/cn6.7639616.com\/hls\/20191204\/64d24c9b0d0d4131e31749f98b057375\/1575434120\/index.m3u8","\u7b2c7\u96c6$http:\/\/cn7.7639616.com\/hls\/20191211\/8dd624fed80ac3443d872fffbeec53c6\/1576039357\/index.m3u8","\u7b2c8\u96c6$http:\/\/cn6.kankia.com\/hls\/20191218\/9eb7be9e294c65f31758c23b43ba1e4f\/1576643068\/index.m3u8","\u7b2c9\u96c6$http:\/\/cn7.kankia.com\/hls\/20191225\/493ee42776d5ea0e8f1384003d07662f\/1577247758\/index.m3u8","\u7b2c10\u96c6$http:\/\/cn7.kankia.com\/hls\/20200101\/bbde121b802e2a24c83a1e775e17e209\/1577851733\/index.m3u8"]}]});';
//        $start = strpos ($res,'{');
//        $last = strrpos($res,'}');
//        $info = json_decode(substr($res,$start,$last-$start+1),true);
//        if($info['title']=='404'){
//            $this->error('未找到视频！');
//        }

        $this->success(['curl'=>$res]);
    }

    function wandhi()
    {
        $tt = (string)($this->request->server('REQUEST_TIME_FLOAT'));
        $tt = str_replace('.','',$tt);
        $tt = substr($tt,0,13);
        if(strpos($this->playurl,'http')){
            $u = 'url=';
        }else{
            $u = 'wd=';
        }
        list($msec, $sec) = explode(' ', microtime());
        $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
        $u .= $this->playurl;
        $url = 'http://vip.wandhi.com/api.php?'.$u.'&cb=jQuery1820'.'_'.$tt.'&_='.$msectime;
        $type =  $this->request->request('type');
        if($type && $type==1){
            $url = 'http://vip.wandhi.com/api.php?'.$this->playurl.'&cb=jQuery1820'.'_'.$tt.'&_='.$msectime;
        }
        $options = array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_ENCODING=>'gzip, deflate',
            CURLOPT_USERAGENT=>$this->header['User-Agent'],
            CURLOPT_REFERER=>'http://vip.62dh.com/?v='.$this->playurl,
            CURLOPT_HTTPHEADER => array(
                'Accept:text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
                'Accept-Language:zh-CN,zh;q=0.9',
                'Cache-Control:no-cache',
                'Connection:keep-alive',
                'Host:vip.wandhi.com',
                'Pragma:no-cache',
                'X-Requested-With:XMLHttpRequest',
            ),
        );
//        $this->success(['curl'=>'jQuery1820_1585552507440({"success":1,"code":0,"info":[{"flag":0,"flag_name":"\u6e901","from":"\u6e901","type":"ckm3u8","id":"7477","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B","img:":"null"},{"flag":0,"flag_name":"\u6e901","from":"\u6e901","type":"ckm3u8","id":"46442","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E7%89%B9%E5%88%AB%E7%AF%87%EF%BC%9A%E8%BF%B7%E9%9B%BE%E5%B2%9B%E5%A4%A7%E5%86%92%E9%99%A9","img:":"null"},{"flag":0,"flag_name":"\u6e901","from":"\u6e901","type":"ckm3u8","id":"26809","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B15%E5%91%A8%E5%B9%B4%E7%BA%AA%E5%BF%B5%E7%89%B9%E5%88%AB%E7%AF%87","img:":"null"},{"flag":0,"flag_name":"\u6e901","from":"\u6e901","type":"ckm3u8","id":"43911","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%8810%EF%BC%9A%E5%BC%BA%E8%80%85%E5%A4%A9%E4%B8%8B","img:":"null"},{"flag":0,"flag_name":"\u6e901","from":"\u6e901","type":"ckm3u8","id":"19151","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E7%89%B9%E5%88%AB%E7%AF%87%E7%A9%BA%E5%B2%9B%E4%B9%8B%E7%AB%A0","img:":"null"},{"flag":0,"flag_name":"\u6e901","from":"\u6e901","type":"ckm3u8","id":"18204","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%881-13%E5%90%88%E9%9B%86","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"33988","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"80276","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B2017%E7%89%B9%E5%88%AB%E7%AF%87%E4%B8%9C%E6%B5%B7","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"80190","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B2016%E5%89%A7%E5%9C%BA%E7%89%88GOLD","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"79051","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%881%EF%BC%9A%E9%BB%84%E9%87%91%E5%B2%9B%E5%86%92%E9%99%A9","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"79050","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%889%EF%BC%9A%E7%BB%BD%E6%94%BE%E5%9C%A8%E5%AF%92%E5%86%AC%E7%9A%84%E5%A5%87%E8%BF%B9%E4%B9%8B%E8%8A%B1","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"79049","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%888%EF%BC%9A%E6%B2%99%E6%BC%A0%E7%9A%84%E7%8E%8B%E5%A5%B3%E4%B8%8E%E6%B5%B7%E8%B4%BC%E4%BB%AC","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"79048","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%887%EF%BC%9A%E6%9C%BA%E5%85%B3%E5%9F%8E%E7%9A%84%E6%9C%BA%E6%A2%B0%E5%B7%A8%E5%85%B5","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"79047","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%885%EF%BC%9A%E8%A2%AB%E8%AF%85%E5%92%92%E7%9A%84%E5%9C%A3%E5%89%91","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"79046","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%884%EF%BC%9A%E6%AD%BB%E4%BA%A1%E5%B0%BD%E5%A4%B4%E7%9A%84%E5%86%92%E9%99%A9","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"66634","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%EF%BC%9A%E7%8B%82%E7%83%AD%E8%A1%8C%E5%8A%A8","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"75863","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E7%89%B9%E5%88%AB%E7%AF%87%EF%BC%9A%E9%BB%84%E9%87%91%E4%B9%8B%E5%BF%83","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"75676","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%882%EF%BC%9A%E5%8F%91%E6%9D%A1%E5%B2%9B%E7%9A%84%E5%86%92%E9%99%A9","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"75675","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%883%EF%BC%9A%E7%8F%8D%E5%85%BD%E5%B2%9B%E7%9A%84%E4%B9%94%E5%B7%B4%E7%8E%8B%E5%9B%BD","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"75674","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%886%EF%BC%9A%E7%8B%82%E6%AC%A2%E7%94%B7%E7%88%B5%E5%92%8C%E7%A5%9E%E7%A7%98%E5%B2%9B","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"52428","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8BSP%E7%A9%BA%E5%B2%9B%E7%AF%87","img:":"null"},{"flag":1,"flag_name":"\u6e902","from":"\u6e902","type":"zuidam3u8","id":"42690","title":"%E6%B5%B7%E8%B4%BC%E7%8E%8B%E5%89%A7%E5%9C%BA%E7%89%88Z","img:":"null"}],"title":"\u6d77\u8d3c\u738b"});"']);
        $ch = new Curl($options);
        $res = $ch->send();
        $this->success(['curl'=>$res]);
    }

    function dhplay()
    {
        $tt = (string)($this->request->server('REQUEST_TIME_FLOAT'));
        $tt = str_replace('.','',$tt);
        $tt = substr($tt,0,13);
        if(strpos($this->playurl,'http') !== false){
            $u = 'url=';
        }else{
            $u = 'wd=';
        }
        list($msec, $sec) = explode(' ', microtime());
        $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
        $u .= $this->playurl;
        $url = 'http://vip.62dh.com/api.php?'.$u.'&cb=jQuery1820'.'_'.$tt.'&_='.$msectime;
        $type =  $this->request->request('type');
        if($type && $type==1){
            $url = 'https://vip.62dh.com/api.php?'.$type.'&cb=jQuery1820'.'_'.$tt.'&_='.$msectime;
        }
        $options = array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_ENCODING=>'gzip, deflate, br',
            CURLOPT_USERAGENT=>$this->header['User-Agent'],
            CURLOPT_REFERER=>'http://vip.62dh.com/?v='.$this->playurl,
            CURLOPT_COOKIE=>'UM_distinctid=1711b26974344e-06f403883230c3-376b4502-1fa400-1711b2697444ee; 033988=0; list_num=0; live_num=; ZDEDebuggerPresent=php,phtml,php3; CNZZDATA1277692379=1330756259-1585297813-https%253A%252F%252Fvip.62dh.com%252F%7C1585536395',
            CURLOPT_HTTPHEADER => array(
                'Accept:text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
                'Accept-Language:zh-CN,zh;q=0.9',
                'Cache-Control:no-cache',
                'Connection:keep-alive',
                'Host:vip.62dh.com',
                'Pragma:no-cache',
                'Sec-Fetch-Mode: cors',
                'Sec-Fetch-Site: same-origin',
                'X-Requested-With:XMLHttpRequest',
            ),
        );
        $ch = new Curl($options);
        $ch->round_ip();
        $res = $ch->send();
        $this->success(['curl'=>$res]);
    }

    function test(){
        var_dump($this->request->server());
        die;
    }
}